package com.lihao.sam.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lihao.sam.dao.HouseResourceSettingDao;
import com.lihao.sam.entity.HouseBasicSetting;
import com.lihao.sam.entity.HouseResourceSetting;
import com.lihao.sam.service.intf.HouseResourceSettingService;
import com.lihao.sam.vo.PageVo;
import com.lihao.sam.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName HouseResourceSettingServiceImpl
 * @Description TODO
 * @Author LiHao
 * @Date 2022/11/23 11:16
 * @Version 1.0
 */
@Service
public class HouseResourceSettingServiceImpl implements HouseResourceSettingService {
    @Resource
    private HouseResourceSettingDao dao;
    @Override
    public R add(HouseResourceSetting resourceSetting) {
        if(dao.add(resourceSetting)>0){
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R update(HouseResourceSetting resourceSetting) {
        if(dao.update(resourceSetting)>0){
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public R delete(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }
        return R.fail();
    }

    @Override
    public PageVo queryPage(int page, int limit, String address,Integer buildingNo, Integer floorNo) {
        PageHelper.startPage(page,limit);
        PageInfo<HouseResourceSetting> pageInfo = new PageInfo<>(dao.selectByWhere(address,buildingNo,floorNo));
        return new PageVo(0,"OK",pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public R deleteBatch(int[] ids) {
        if (dao.delBatch(ids) > 0) {
            return R.ok();
        }
        return R.fail();
    }
}
